package impl

import (
	"context"
	"wms/entity"
	"wms/glo"
	"wms/service/model"
	"wms/service/request"
	"wms/util"
)

type DictService struct {
}

var DictSrvImpl DictService

func (s *DictService) List(ctx context.Context, arg request.QueryDictRequest) []*model.Dict {
	var entities []*entity.Dict
	_db := glo.Db_wms.Model(&entity.Dict{})
	if arg.BizType > 0 {
		_db = _db.Where("biz_type = ?", arg.BizType)
	}
	if len(arg.DictName) > 0 {
		_db = _db.Where("dict_name LIKE ?", "%"+arg.DictName+"%")
	}
	if err := _db.Find(&entities).Error; err != nil {
		panic("sql err" + err.Error())
	}
	//
	modelListOut := make([]*model.Dict, 0, len(entities))
	for _, tmp := range entities {
		_w := new(model.Dict)
		util.CopyStruct(_w, tmp)
		modelListOut = append(modelListOut, _w)
	}
	return modelListOut
}
